﻿using NMock2;
using NMock2.Matchers;

namespace NMock3.Tests
{
	[NUnit.Framework.TestFixture]
	public class SetPropertyTests
	{
		MockFactory factory = new MockFactory();
		private Mock<IHaveProperties> mock;

		[NUnit.Framework.SetUp]
		public void TestInit()
		{
			mock = factory.CreateMock<IHaveProperties>();
		}

		[NUnit.Framework.TearDown]
		public void TestClean()
		{
			factory.VerifyAllExpectationsHaveBeenMet();
		}

		[NUnit.Framework.Test]
		public void ReadOnlyTest()
		{
			mock.Expects.One.GetProperty(m => m.ReadOnly).WillReturn(1);
			mock.Expects.One.GetProperty(m => m.ReadOnly).Will(Return.Value(2));
			mock.Expects.One.GetProperty(m => m.ReadOnly).Matching(new TypeMatcher(typeof (int))).Will(Return.Value(3));
			mock.Expects.One.GetProperty(m => m.ReadOnly, 4);

			int i = mock.MockObject.ReadOnly;
			NUnit.Framework.Assert.AreEqual(1, i);
			
			i = mock.MockObject.ReadOnly;
			NUnit.Framework.Assert.AreEqual(2, i);
			
			i = mock.MockObject.ReadOnly;
			NUnit.Framework.Assert.AreEqual(3, i);
			
			i = mock.MockObject.ReadOnly;
			NUnit.Framework.Assert.AreEqual(4, i);
		}

	}

	public interface IHaveProperties
	{
		int ReadOnly { get; }
		int WriteOnly { set; }
		int ReadWrite { get; set; }
	}
}
